// 线性DP acwing.898 数字三角形
#include<bits/stdc++.h>
using namespace std;

const int N = 510, INF = 0x3f3f3f3f;

int a[N][N];
int f[N][N];
int n;

int main()
{
    cin >> n;
    memset(f, -INF, sizeof f);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            cin >> f[i][j];
            if (i >= 2) f[i][j] += max(f[i - 1][j - 1], f[i - 1][j]);
        }
    }
   
    int ret = -INF;
    for (int i = 1; i <= n; i++) {
        ret = max(ret, f[n][i]);
    }
    cout << ret << endl;
    return 0;
}